package ch03.demo.dao2.impl;

import ch03.demo.dao2.Buyer;
import org.apache.log4j.Logger;

import java.lang.reflect.Proxy;


public class IntermediaryJdkProxyFactory {
     static Logger logger=Logger.getLogger(IntermediaryJdkProxyFactory.class);
    public static <T> T create(Object target){
        IntermediaryInvocationHandler handler=new IntermediaryInvocationHandler();
        handler.setTarget(target);
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),handler);
    }

    public static void main(String[] args) {
        Buyer buyer=IntermediaryJdkProxyFactory.create(new RealBuyer());
        String result=buyer.havealook();
        logger.debug(result);

    }
}
